package info.motteke.net;

import java.io.Serializable;

public class Cookie implements Serializable {

    /**
     *
     */
    private static final long serialVersionUID = 7448100033570299805L;

    private CookieBuilder builder;

    private Cookie(CookieBuilder builder){
        this.builder = builder;
    }

    public static CookieBuilder of(String name, String value){
        return new CookieBuilder(name, value);
    }


    public String getDomain() {
        return builder.getDomain();
    }

    public long getMaxAge() {
        return builder.getMaxAge();
    }

    public String getName() {
        return builder.getName();
    }

    public String getPath() {
        return builder.getPath();
    }

    public String getValue() {
        return builder.getValue();
    }

    public boolean isSecure() {
        return builder.isSecure();
    }

    public static class CookieBuilder {
        private final String name;

        private final String value;

        private long maxAge;

        private String domain;

        private String path;

        private boolean secure = false;

        private CookieBuilder(String name, String value){
            this.name = name;
            this.value = value;
        }

        public CookieBuilder maxAge(long maxAge){
            this.maxAge = maxAge;
            return this;
        }

        public CookieBuilder domain(String domain){
            this.domain = domain;
            return this;
        }

        public CookieBuilder path(String path){
            this.path = path;
            return this;
        }

        public CookieBuilder secure(){
            this.secure = true;
            return this;
        }

        public String getName() {
            return name;
        }

        public String getValue() {
            return value;
        }

        public long getMaxAge() {
            return maxAge;
        }

        public String getDomain() {
            return domain;
        }

        public String getPath() {
            return path;
        }

        public boolean isSecure() {
            return secure;
        }

        public Cookie build(){
            return new Cookie(this);
        }
    }

}
